/*
ID: icerupt1
PROG: runround
LANG: C++11
*/
#include <fstream>
#include <iostream>
#include <algorithm>
#include <string>

std::ifstream fin {"runround.in" };
std::ofstream fout{"runround.out"};

bool unique(int s)
{
	bool judge[10];
	std::fill(judge, judge + 10, 0);
	for (; s; s /= 10) {
		if (judge[s%10]) return false;
		judge[s % 10] = true;
	}
	return true;
}

bool runaround(std::string x)
{
	bool judge[10];
	std::fill(judge, judge + 10, 0);
	int len = x.size(), pos = 0;
	for (int i = 0; i < len - 1; i++) {
		int tmp = x[pos] - '0';
		judge[tmp] = true;
		if (judge[x[(pos + tmp) % len] - '0']) return false;
		pos = (pos + tmp) % len;
	}
	return (pos + x[pos] - '0') % len == 0;
}

int main()
{
	unsigned int n;
	fin >> n;
	for (int i = n+1; ; i++)
		if (unique(i) && runaround(std::to_string(i))) {
			std::cout << i << '\n';
			fout << i << '\n';
			break;
		}
}
